package com.gonsin.gmessage.logic.model;

import io.swagger.annotations.ApiModel;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
@ApiModel("消息结构")
public class GMessageModel implements Cloneable{

    private String head = "gonsin";

    /**
     * 发送的域
     */
    private transient String zoom;

    /**
     * 发送端信息
     */
    private TerminalInfo terminal;

    public String getHead() {
        return head;
    }

    public void setHead(String head) {
        this.head = head;
    }

    public String getZoom() {
        return zoom;
    }

    public void setZoom(String zoom) {
        this.zoom = zoom;
    }

    public MqttCmd getCmd() {
        return cmd;
    }

    public void setCmd(MqttCmd cmd) {
        this.cmd = cmd;
    }

    public Map<String, Object> getArgs() {
        return args;
    }

    public void setArgs(Map<String, Object> args) {
        this.args = args;
    }

    private MqttCmd cmd = new MqttCmd();

    private Map<String, Object> args = new HashMap<>();

    private GMessageModel(){}

    public GMessageModel firstCmd(String firstCmd){
        cmd.firstcmd = firstCmd;
        return this;
    }

    public GMessageModel subCmd(String subcmd){
        cmd.subcmd = subcmd;
        return this;
    }

    public GMessageModel response(){
        cmd.response = 1;
        return this;
    }

    public GMessageModel args(String key, Object value){
        args.put(key, value);
        return this;
    }

    public GMessageModel zoom(String zoom){
        this.zoom = zoom;
        return this;
    }

    public GMessageModel args(Map<String, Object> object){
        args.putAll(object);
        return this;
    }

    public static GMessageModel create(String firstCmd, String subCmd){
        GMessageModel mqttMessage = new GMessageModel();
        mqttMessage.getCmd().setFirstcmd(firstCmd);
        mqttMessage.getCmd().setSubcmd(subCmd);
        return mqttMessage;
    }

    @Data
    public static class MqttCmd {

        private String firstcmd;

        private String subcmd;

        public String getFirstcmd() {
            return firstcmd;
        }

        public void setFirstcmd(String firstcmd) {
            this.firstcmd = firstcmd;
        }

        public String getSubcmd() {
            return subcmd;
        }

        public void setSubcmd(String subcmd) {
            this.subcmd = subcmd;
        }

        public int getResponse() {
            return response;
        }

        public void setResponse(int response) {
            this.response = response;
        }

        private int response;
    }

    @Data
    public class MqttDevice {

        private int id;

        private int devid;

        private int type;

        private String version;

    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
